package com.qfedu.dtboot.controller;

import com.qfedu.dtboot.entity.SysRole;
import com.qfedu.dtboot.service.SysRoleService;
import com.qfedu.dtboot.utils.DataGridResult;
import com.qfedu.dtboot.utils.Query;
import com.qfedu.dtboot.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/sys/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @GetMapping("/list")
    @RequiresPermissions(value ={""})
    public DataGridResult getPageList(@RequestParam Map<String,Object> params)
    {
        Query query = new Query(params);
        DataGridResult pageList = sysRoleService.getPageList(query);
        return  pageList;
    }

    @PostMapping("/del")
    @RequiresPermissions(value = {""})
    public R delete(@RequestBody Long[] ids)
    {
        sysRoleService.deleteBatch(ids);
        return R.ok();
    }
    @PostMapping("/save")
    @RequiresPermissions(value ={"sys:role:save"})
    public R save(@RequestBody SysRole role)
    {
        sysRoleService.save(role);
        return R.ok();
    }
    @GetMapping("/info/{roleId}")
    @RequiresPermissions(value = {""})
    public R info(@PathVariable("roleId") Long roleId)
    {
        SysRole sysRole = sysRoleService.queryObject(roleId);

        return R.ok().put("role",sysRole);
    }

    @PostMapping("/update")
    @RequiresPermissions(value ={"sys:role:update"})
    public R update(@RequestBody SysRole sysRole)
  {
      sysRoleService.update(sysRole);
      return R.ok();
  }

}
